/*
 * VideoCamera.cpp
 *
 *  Created on: 2014-4-9
 *      Author: root
 */
#include "VideoCamera.hh"
VideoCamera*VideoCamera::createNew(int Width ,int Height)
{
	if((0 < Width) && (0 < Height))
		{
			return new VideoCamera(Width, Height);
		}
		else
		{
			return NULL;
		}

}

VideoCamera::VideoCamera(int Width ,int Height)
{
	outFrameLen = 0;
	usWidth = Width;
	usHeight = Height;
	capture_buf = new FRAME_BUF;
	video_Cpature = VideoCapture::createNew(usWidth,usHeight);
	video_Encode = VideoEncode::createNew(usWidth,usHeight);
	pOutFrame = new uint8_t[usWidth*usHeight*3/1];
	pInFrame = new uint8_t[usWidth*usHeight*3/1];
}

VideoCamera::~VideoCamera(void)
{
	delete[] pInFrame;
	delete[] pOutFrame;
	delete video_Cpature;
	delete video_Encode;
	delete capture_buf;
}

void VideoCamera::CameraInit(const char*Device_name, int fps)
{
	video_Cpature->Capture_Device_init(Device_name);//摄像头初始化
	video_Encode->init_encoder(fps);//编码设备初始化

}

void VideoCamera::CameraDestory(void)
{
	video_Cpature->Capture_Device_release();
	//释放编码器
	video_Encode->release_encoder();
}

void VideoCamera::GetNextFrame(void)
{
	if (video_Cpature->Capture_Frame(capture_buf))
	{
		memcpy(pInFrame, capture_buf->start, capture_buf->length);
		video_Encode->encode_op.picture->i_pts++;
		outFrameLen = video_Encode->encode_frame(-1,pInFrame,pOutFrame);
	}
}
	/*
public:
	uint8_t *pOutFrame;
	int outFrameLen;
private:
	VideoEncode *video_Encode;
	VideoCapture *video_Cpature;

	*/
